import request from "@/utils/request";

export const sendCodeAPI = (mobile: string) => {
  return request({ url: "/v1_0/sms/codes/" + mobile });
};

export const loginAPI = (mobile: string, code: string) => {
  return request({
    url: "/v1_0/authorizations",
    method: "post",
    data: {
      mobile,
      code,
    },
  });
};

export const getUserInfoAPI = () => request({ url: "/v1_0/user" });

export const getProfileAPI = () => {
  return request({ url: "/v1_0/user/profile" });
};

export const uploadPhotoAPI = (formData: FormData) => {
  return request({ url: "/v1_0/user/photo", method: "patch", data: formData });
};

// Partial 内置的泛型工具
// 作用: 将对象的键全部转为可选
export const updateProfileAPI = (profile: Partial<IProfile>) => {
  return request({ url: "/v1_0/user/profile", method: "patch", data: profile });
};
